# -*- coding: utf-8 -*-
from sqlalchemy.orm import Session
from .model import ConversationLog

def create_conversation_log(db: Session, question: str, thinking: str, response: str, user_id: str, keyword: str, is_builtin: int):
    db_conversation_log = ConversationLog(question=question, thinking=thinking, response=response, user_id=user_id, keyword=keyword, is_builtin=is_builtin)
    db.add(db_conversation_log)
    db.commit()
    db.refresh(db_conversation_log)
    return db_conversation_log

def get_conversation_logs(db: Session, user_id: str, skip: int = 0, limit: int = 100):
    return db.query(ConversationLog).filter(ConversationLog.user_id == user_id).offset(skip).limit(limit).all()  # 根据 user_id 过滤查询结果


# 根据id查询详情
def get_conversation_log(db: Session, data_id: int):
    return db.query(ConversationLog).filter(ConversationLog.id == data_id).first()

# 查询表格全部内置数据记录的关键词信息
def get_conversation_logs_keyword(db: Session):
    return db.query(ConversationLog.id, ConversationLog.keyword).filter(ConversationLog.is_builtin == 0).all()
